package com.sanweibook.jhook.web.util;

import com.sanweibook.jhook.common.util.SpringContextAware;
import com.sanweibook.jhook.shiro.authc.UserCredentialsMatcher;
import com.sanweibook.jhook.shiro.hash.UserSimpleHash;
import org.apache.shiro.authc.UsernamePasswordToken;

/**
 * Created by twg on 2017/4/15.
 */
public final class UsernamePasswordTokenUtils {

    public static UserSimpleHash doPassword(String name, String password) {
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(name, password);
        UserCredentialsMatcher userCredentialsMatcher = (UserCredentialsMatcher) SpringContextAware.getBean("userCredentialsMatcher");
        UserSimpleHash simpleHash = userCredentialsMatcher.doPassword(usernamePasswordToken);
        return simpleHash;
    }

    public static void main(String[] args) {
        UserSimpleHash simpleHash = UsernamePasswordTokenUtils.doPassword("twg","twg12345");
        System.out.println("pass : "+simpleHash.toHex());
        System.out.println("salt : "+simpleHash.getRandomSalt());
    }
}
